package com.oscar.ehome.view.pageview.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.base.C;
import com.oscar.ehome.bean.pagebean.MemberBean;
import com.oscar.ehome.provider.gildeimage.GildeUtils;
import com.oscar.ehome.utils.basethem.TintManager;
import com.oscar.ehome.utils.system.SystemConfigFactory;
import com.oscar.ehome.utils.util.DateUtil;

import org.apache.commons.lang.StringUtils;

import java.util.List;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/7/21
 * 已认证的会员
 */

public class MemberapproAdapter extends BaseAdapter {
    private List<MemberBean.MemberMessageBean> specailList;
    private LayoutInflater mInflater;
    private Context mContext = null;
    OnMemberClickslister onClickListener;

    public MemberapproAdapter(Context context, List<MemberBean.MemberMessageBean> specailList) {
        this.mContext = context;
        this.specailList = specailList;
        mInflater = LayoutInflater.from(context);
    }

    public void setLists(List<MemberBean.MemberMessageBean> specailList) {
        this.specailList = specailList;
        notifyDataSetChanged();
    }

    /**
     * 设置回调接口
     *
     * @param onClickListener
     */
    public void setOnMemberClicksListener(OnMemberClickslister onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface OnMemberClickslister {
        public void OnClickMem(int postion);
    }

    @Override
    public int getCount() {
        return specailList.size();
    }

    @Override
    public Object getItem(int position) {
        return specailList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.adapter_approvemember, null);
            holder = new ViewHolder();
            holder.mem_phone = (TextView) convertView.findViewById(R.id.mem_phone);
            holder.mem_name = (TextView) convertView.findViewById(R.id.mem_name);
            holder.mem_img = (ImageView) convertView.findViewById(R.id.mem_img);
            holder.mem_days_text = (TextView) convertView.findViewById(R.id.mem_days_text);
            holder.mem_time_text = (TextView) convertView.findViewById(R.id.mem_time_text);
            holder.mem_pay = (ImageView) convertView.findViewById(R.id.mem_pay);
            convertView.setTag(holder); //
        } else {
            holder = (ViewHolder) convertView.getTag(); //
        }

        if (specailList.size() > 0) {
            MemberBean.MemberMessageBean bean = specailList.get(position);
            if (bean != null) {
                String path = C.qiniu_ip + bean.getPhoto();
                GildeUtils.loadUrlImage4(path, holder.mem_img, mContext);
                holder.mem_name.setText(bean.getName());
                holder.mem_phone.setText(bean.getMobile());

                holder.mem_phone.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
                holder.mem_phone.getPaint().setAntiAlias(true);//抗锯齿

                holder.mem_phone.setTextColor(Color.parseColor(SystemConfigFactory.getInstance(mContext).getSystemConfig().getColor()));

                if (bean.getAuthenTime() != null && StringUtils.isNotEmpty(bean.getAuthenTime())) {
                    holder.mem_days_text.setText(DateUtil.strToDate(bean.getAuthenTime()));
                } else {
                    holder.mem_days_text.setText("暂无");
                }
                if (bean.getCreateDate() != null && StringUtils.isNotEmpty(bean.getCreateDate())) {
                    String dates = DateUtil.strToDate(bean.getCreateDate());
                    holder.mem_time_text.setText(dates);
                } else {
                    holder.mem_time_text.setText("暂无");
                }
                String pay = bean.getIsPay();//1是已支付
                if ("1".equals(pay)) {
                    holder.mem_pay.setVisibility(View.VISIBLE);
                } else {
                    holder.mem_pay.setVisibility(View.GONE);
                }
                holder.mem_phone.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onClickListener.OnClickMem(position);
                    }
                });
            }
        }
        return convertView;
    }


    class ViewHolder {
        TextView mem_name;
        TextView mem_phone;
        ImageView mem_img;
        TextView mem_days_text;
        TextView mem_time_text;
        ImageView mem_pay;
    }
}
